<template>
    <div class="container">
        <div class="row col-md-8 col-md-offset-3">


            <div class="form-horizontal">


                <div class="form-group">
                    <label  class="col-sm-2 control-label">邮箱</label>
                    <div class="col-sm-5">
                        <input type="text"
                               name="email"
                               class="form-control" required v-model="email" placeholder="请输入邮箱">
                    </div>
                </div>


                <div class="form-group">
                    <label  class="col-sm-2 control-label">用户名</label>
                    <div class="col-sm-5">
                        <input type="text"
                               name="email"
                               class="form-control" required v-model="username" placeholder="请输入用户名">
                    </div>
                </div>
                <div class="form-group">
                    <label  class="col-sm-2 control-label">密码</label>
                    <div class="col-sm-5">
                        <input type="password"
                               
                               class="form-control" v-model="password" placeholder="请输入密码">
                    </div>
                </div>

                <div class="form-group">
                    <label  class="col-sm-2 control-label">确认密码</label>
                    <div class="col-sm-5">
                        <input type="password"
                               
                               class="form-control" v-model="twopassword" placeholder="请输入密码">
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-offset-1 col-sm-6" style="margin-top: 40px;">
                        <button type="button" class="btn btn-default btn-success" style="float: left;margin-left: -15px;" @click="wl_register()" >注册</button>
                        <a type="button" class="btn btn-default btn-success" 
                        style="float: right;color:white;"
                         href="/#/login">去登陆</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import conf from '../layout/conf.vue'//引用模块进来
    export default {
        mounted() {
            console.log("开始!");


        },
        data(){
            return {
                list: {},
                  email:"",
                password:"",
                username:"",
                twopassword:"",
                 url:conf.url+"/user/register/index/",


            }


        },

        methods:{

            wl_register(){
                if(this.email=="" ||this.password==""||this.username==""||this.twopassword==""){
                        this.message("","请将内容全部填写");
                        return;
                }

                if(this.password!=this.twopassword){
                    this.message("","两次密码不一样!");
                        return;
                }


                  var params = new URLSearchParams();
                params.append('user_email',this.email);
                params.append('user_pwd', this.password);
                params.append('user_name', this.username);
                
                this.axios.post(this.url,params).then(response=>{
                    console.log(response);
                     var info=response.data;
                    if(info.status=="error"){
                      this.message("no",info.message); 
                    }

                    if(info.status==1){
                      this.message("ok",info.message); 
                       setTimeout(function () {
                                location.href="/#/login";
                            },1000)
                    }

                });
                
            }
        }


    }
</script>
